<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once '../comm/wjt.php';
include_once 'check.php';

if($_GET['type'] == 'ajax'){
	$uploaddir = "../umik_u/images/shopauth/";
	$types = array("jpg","gif","bmp","jpeg","png");
	$type = substr(strrchr($_FILES['license']['name'],'.'),1);
	if(!in_array(strtolower($type), $types)){
		$text=implode('.',$types);
		echo "您只能上传以下类型文件: ",$text,"<br>";die;
	}else{
		$filename=explode(".",$_FILES['license']['name']);
		$time=date("m-d-H-i-s");
		$filename[0]=$time;
		$name=implode(".",$filename);
		$uploadfile=$uploaddir.$name;
	}
	move_uploaded_file($_FILES['license']['tmp_name'],$uploadfile);
	$time = date("Y-m-d H:i:s",time());
	$ajaxsql = "INSERT INTO ".$BIAOTOU."shopauth (`username`,`authtype`,`authtime`,`conditions`,`license`) VALUES ('{$_SESSION["duoduouser"]}','{$_POST['authtype']}','{$time}','{$_POST['conditions']}','{$name}')";
	if(mysql_query($ajaxsql)){
		echo "succ";
	}else{
		echo "fail";
	}
	die;
}
//查询默认级别
$sqlDefault="select * from ".$BIAOTOU."shoplevel where `default` = '1'";
$rs1 = mysql_query($sqlDefault);
$defalutArr = mysql_fetch_array($rs1);

foreach($_POST as $k => $v){
	$post[$k] = $v; 
}
if(!empty($post['submit'])){
	$insertarr = array();
	$insertarr['Id'] = $_SESSION['dduserid'];
	$insertarr['number'] = sprintf("%05d", $insertarr['Id']);
	$insertarr['ddshopname'] = $post['shopname'];
	$insertarr['regtime'] = date("Y-m-d H:i:s",time());
	$insertarr['province'] = $post['province'];
	$insertarr['city'] = $post['city'];
	$insertarr['business'] = $post['business'];
	$insertarr['comment '] = implode(",", $post['type']);
	$insertarr['contact_username'] = $post['contact_username'];
	$insertarr['contact_mobile'] = $post['contact_mobile'];
	$insertarr['url'] = $post['url'];
	$insertarr['username'] = $_SESSION["duoduouser"];
	$insertarr['level'] = $defalutArr['id'];
	$insertarr['money'] = "100";
	sql_insert_one("usershop",$insertarr);
}else{
	
}
$sql = "select * from ".$BIAOTOU."usershop where `Id` = ".$_SESSION['dduserid'];
$res = mysql_query($sql);
$num = mysql_num_rows($res);
if($num != 0){
	$apply = "YES";
	while ($row = mysql_fetch_array($res)){
		$active = $row['active'];
		$shop_authapply = $row['authapply'];
		$shop_authentication = $row['authentication'];
		$number = $row['number'];
	}	
}else{
	$apply = "NO";
}
//调用行业信息
$sql="select * from ".$BIAOTOU."malltype";
$business = mysql_query($sql);

$sql = "SELECT * FROM ".$BIAOTOU."dhlist where recommend=1 and hide=0 order by sort desc, addtime desc limit 5";
$dhlist = mysql_query($sql);


$tag="center";
if($apply == "YES"){
	if($active == 0){
		include '../template/'.MOBAN.'/shopregistered.tpl.php';
	}else{
		$typeRes = mysql_query("SELECT * FROM ".$BIAOTOU."shoptype");
		$q = "SELECT * FROM ".$BIAOTOU."user where ddusername='".$_SESSION["duoduouser"]."'";
		$rs = mysql_query($q);
		$row = mysql_fetch_object($rs);
		$money=$row->money;
		$jifen=$row->jifen;
		$yitixian=$row->yitixian;
		$zfb=$row->zfb;
		$dengji=$row->dengji;
		$txstate=$row->txstate;
		$ddpassword=$row->ddpassword;
		include '../template/'.MOBAN.'/shopallowed.tpl.php';
	}
}else{
	include '../template/'.MOBAN.'/shopunregister.tpl.php';
}
mysql_close();

function sql_insert_one($table,$filed_arr){
	global $BIAOTOU;
	$field="";
	$values="";
	foreach($filed_arr as $k=>$v){
		$field = "`".$k."`,".$field;
		$values = "'".$v."',".$values;
	}
	$field=substr($field,0,strlen($field)-1);
	$values=substr($values,0,strlen($values)-1);
	$sql="insert into $BIAOTOU$table($field) values ($values);";
	$query=mysql_query($sql);
	if($query) return 1;
	else return mysql_error();
}
?>

